package mySql;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class delete_goods extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		doPost(request, response);
		out.close();
	}


	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		
		response.setContentType("text/html;charset=gb2312");
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("UTF-8");
		String login_name="root";
		String login_password="2014121167";
		String driverClass="com.mysql.jdbc.Driver";
		String url="jdbc:mysql://localhost:3306/test";
		Connection con=null;
		PreparedStatement pst=null;
		int rs;
		
		
		DBConnection dbcon=new DBConnection(driverClass,url,login_password,login_name);
		try
		{
			
				con=dbcon.getConnection();
				pst=con.prepareStatement("delete from goods_detail where name="+"'"+new String(request.getParameter("id").getBytes("iso8859-1"), "utf-8")+"'");
				rs=pst.executeUpdate();
				response.setHeader("refresh", "2;URL="+"http://localhost:8080/practise/jsp/manage_delete.jsp");
				out.print("删除成功！");
		}
		catch (Exception e) {
			e.getStackTrace();
		}
		
		
		
		
		
		out.close();
	}

}
